package com.xatz.scanner

import android.app.Application
import android.content.Context
import com.pgyersdk.Pgyer
import com.pgyersdk.PgyerActivityManager
import com.pgyersdk.crash.PgyCrashManager
import com.pgyersdk.crash.PgyerCrashObservable
import timber.log.Timber


/**
 * author: tdq
 * date: 2021/7/19
 * description:
 */
class App : Application() {

    companion object {
        private var mContext: Application? = null
        fun getContext(): Context {
            return mContext!!
        }
    }

    override fun onCreate() {
        super.onCreate()
        mContext = this
        initTimber()
        PgyCrashManager.register()
        PgyerCrashObservable.get().attach { thread, throwable -> }
        PgyerActivityManager.set(this)
    }

    private fun initTimber() {
        if (BuildConfig.DEBUG) {
            Timber.plant(Timber.DebugTree())
        }
    }

    override fun attachBaseContext(base: Context?) {
        super.attachBaseContext(base)
        Pgyer.setAppId("0cf8716e791a2495c719fe373fecbf14")
    }

}